<template>
  <!-- 单价在订单中维护 -->
  <div>
    <el-checkbox
      :disabled="[1, 2, 3].includes(stockOutType) || readonly"
      v-model="checkedData"
      :true-label="1"
      :false-label="0"
      @change="changeData"
    ></el-checkbox>
  </div>
</template>
<script>
import nonStandardService from '@/services/nonStandardService'
import eventBus from '@/assets/utils/eventBus.js'
export default {
  name: 'orderUpholdFlag',
  props: {
    detail: {
      type: Object,
      default: () => {
        return {}
      },
    },
    value: [Object, String],
    disabled: Boolean,
    parameter: {
      type: Object,
      default: () => {
        return {}
      },
    },
    data: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      checkedData: 0,
      selectData: null,
      stockOutType: null,
      readonly: false,
    }
  },
  created() {
    this.readonly = Boolean(this.$route.query.readonly)
    if (this.value) {
      this.setData()
    }
    eventBus.$on('stockOutTypesChange', (val) => {
      this.stockOutType = val
      this.checkedData = 0
      this.changeData(this.checkedData)
    })
  },
  methods: {
    changeData(val) {
      this.$emit('input', String(this.checkedData))
      eventBus.$emit('orderUpholdFlagChange', val)
      this.selectData = val === 1 ? this.$t('是') : this.$t('否')
    },
    setData() {
      let stockOutTypes =
        this.data.stockOutTypes && this.data.stockOutTypes.indexOf('{') === 0
          ? JSON.parse(this.data.stockOutTypes)
          : {}
      this.stockOutType = stockOutTypes.checkedData
      this.selectData = JSON.parse(this.value).value
      this.checkedData = JSON.parse(this.value).checkedData
    },
    getData() {
      return {
        value: this.selectData,
        checkedData: this.checkedData,
      }
    },
  },
}
</script>
